package com.example.project.service.impl;

import com.example.project.service.UploadService;
import com.example.project.util.FileUtils;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.io.InputStream;

@Service
public class UploadServiceImpl implements UploadService {

    public String upload(String uploadRoot, InputStream inputStream, String type) throws IOException {
        String fileName = FileUtils.getFileName(type);
        // 保存
        FileUtils.saveFile(inputStream, uploadRoot + "/" + fileName);

        return fileName;
    }

    //根据路径替换
    public void updateLoad(String imgUrl, InputStream inputStream) throws IOException{
//        FileUtils.delete(imgUrl);
        // 保存
        FileUtils.saveFile(inputStream, imgUrl);

    }

}
